package com.orilore.gb.web;

import java.io.IOException;
import java.net.URLEncoder;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.orilore.dto.XEployeeDto;
import com.orilore.gb.biz.XEmployeeBiz;

/**
 * Servlet implementation class DeleteEmployeeServlet
 */
public class DeleteEmployeeServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public DeleteEmployeeServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		request.setCharacterEncoding("UTF-8");
		
         String name = request.getParameter("name");
         
         
         System.out.println("$$$$$$$$$$$$$$$$"+name);
		 
         String beginage = request.getParameter("beginage");
		 
		 String endage = request.getParameter("endage");
		 
		 String sex = request.getParameter("sex");
		 
		 String did = request.getParameter("did");
		 
		 String address = request.getParameter("address");
		
        String id = request.getParameter("id");
        
        String curpage = request.getParameter("curpage");
		
		XEmployeeBiz  biz = new XEmployeeBiz();
		
		boolean flag =biz.removeXEmployee(Integer.parseInt(id));
		
		int forwardpage = Integer.parseInt(curpage);
		
		
		
	   List<XEployeeDto> list =   biz.queryPage(name, sex, beginage, endage, address, did, Integer.parseInt(curpage));
		
		if(list.size()==0) {
			
			
			if(forwardpage>1) {
			
			forwardpage = forwardpage-1;
			
			}
		
			
			
		}
		
		
		
		if(flag) {
			
			System.out.println("QueryEmployeePageServlet?curpage="+forwardpage+"&name="+name+"&sex="+sex+"&beginage="+beginage+"&endage="+endage+"&did="+did+"&address="+address);
			
			response.sendRedirect("QueryEmployeePageServlet?curpage="+forwardpage+"&name="+URLEncoder.encode(name, "UTF-8")+"&sex="+sex+"&beginage="+beginage+"&endage="+endage+"&did="+did+"&address="+URLEncoder.encode(address, "UTF-8"));
			 
			
		}
		
		
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
